/*
 * (C) 2012	APUE & Sheng Yi
 * Clear and Set file descriptors
 */
#include "apue.h"
#include <fcntl.h>

void set_fl(int filedes, int val)	/* flags are file status flags to turn on */
{
	int flags;
	if ((flags = fcntl(filedes, F_GETFL, 0) < 0))
			err_quit("fcntl F_GETFL error");

	flags |= val;	/* turn on */

	if (fcntl(filedes, F_SETFL, flags) < 0)
		err_quit("fcntl F_SETFL error");
}

void clr_fl(int filedes, int val)
{
	int flags;
	if ((flags = fcntl(filedes, F_GETFL, 0) < 0))
		err_quit("fcntl F_GETFL error");

	flags &= (~val);	/* turn off */

	if (fcntl(filedes, F_SETFL, flags) < 0)
		err_quit("fcntl F_SETFL error");
}
